package com.hbnu.exercise.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket implements Runnable
{
    private int ticket = 25;
//    private static final ReentrantLock lock = new ReentrantLock();
    @Override
    public void run()
    {
        while (true)
        {
//          lock.lock();
            synchronized (this)
            {
                if (ticket > 0)
                {
                    System.out.println(Thread.currentThread().getName() + "卖出了" + ticket + "号票");
                    ticket--;
                }
                else
                    break;
            }
//          lock.unlock();
        }
    }
}
